package com.zbowen.invoice.base.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.zbowen.invoice.base.dto.IvaBookDto;
import com.zbowen.invoice.base.service.IvaBookService;
import com.zbowen.invoice.repository.mapper.IvaBookMapper;
import com.zbowen.invoice.repository.po.IvaBook;
import org.apache.commons.beanutils.BeanUtils;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;

import java.lang.reflect.InvocationTargetException;
import java.util.LinkedList;
import java.util.List;

@Service
public class IvaBookServiceImpl extends ServiceImpl<IvaBookMapper, IvaBook> implements IvaBookService {

    @Override
    public IvaBookDto findIvaBookByVatino(String vatino) {
        LambdaQueryWrapper<IvaBook> queryWrapper = Wrappers.lambdaQuery(IvaBook.class);
        queryWrapper.eq(StringUtils.isNotBlank(vatino), IvaBook::getVatino, vatino);
        IvaBook ivaBook = getOne(queryWrapper);
        IvaBookDto ivaBookDto = new IvaBookDto();
        try {
            BeanUtils.copyProperties(ivaBook, ivaBookDto);
        } catch (IllegalAccessException | InvocationTargetException e) {
            throw new RuntimeException(e);
        }
        return ivaBookDto;
    }

    @Override
    public List<IvaBookDto> queryPage(IvaBookDto ivaBookDto) {
        List<IvaBook> list = list();
        // 转换
        LinkedList<IvaBookDto> ivaBookDtos = new LinkedList<>();
        return ivaBookDtos;
    }
}
